package com.mttang.util;

import java.net.URLDecoder;
import java.net.URLEncoder;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class FusionChartXMLUtil {
	     private Document document = null;  
	     public Document getDocument() {  
	         return document;  
	     }  
	     /** 
	      * 构造方法，初始化Document 
	      */  
	     public FusionChartXMLUtil() {  
	         document = DocumentHelper.createDocument();  
	     }  
	     /** 
	      * 生成根节点 
	      *  
	      * @param rootName 
	      * @return 
	      */  
	     public Element addRoot(String rootName) {  
	         Element root = document.addElement(rootName);  
	         return root;  
	     }  
	     /** 
	      * 生成节点 
	      *  
	      * @param parentElement 
	      * @param elementName 
	      * @return 
	      */  
	     public Element addNode(Element parentElement, String elementName) {  
	         Element node = parentElement.addElement(elementName);  
	         return node;  
	     }  
	     /** 
	      * 为节点增加一个属性 
	      *  
	      * @param thisElement 
	      * @param attributeName 
	      * @param attributeValue 
	      */  
	     public void addAttribute(Element thisElement, String attributeName,  
	             String attributeValue) {  
	         thisElement.addAttribute(attributeName, attributeValue);  
	     }  
	     /** 
	      * 为节点增加多个属性 
	      *  
	      * @param thisElement 
	      * @param attributeNames 
	      * @param attributeValues 
	      */  
	     public void addAttributes(Element thisElement, String[] attributeNames, String[] attributeValues) {  
	         for (int i = 0; i < attributeNames.length; i++) {  
	             thisElement.addAttribute(attributeNames[i], attributeValues[i]);  
	         }
	     }  
	     /** 
	      * 增加节点的值 
	      *  
	      * @param thisElement 
	      * @param text 
	      */  
	     public void addText(Element thisElement, String text) {  
	         thisElement.addText(text);  
	     }  
	     /** 
	      * 获取最终的XML 
	      *  
	      * @return 
	      * @throws IOException 
	      */  
	     public String getXML() {  
	         return document.asXML().substring(39);  
	     } 
	     
	     
	     public static void main(String[] args) {
//	    	 FusionChartXMLUtil xml = new FusionChartXMLUtil();
//	    	 Element chart = xml.addRoot("chart");  
//	    	          xml.addAttribute(chart, "caption", "访问统计");  
//	    	          xml.addAttribute(chart, "subCaption", "浏览器类型统计");  
//	    	          xml.addAttribute(chart, "basefontsize", "12");  
//	    	          xml.addAttribute(chart, "xAxisName", "游戏");  
//	    	          xml.addAttribute(chart, "yAxisName", "访问数量");  
//	    	 Element set1 = xml.addNode(chart, "set");
//	    	 set1.addAttribute("label", "凡人修真");  
//	    	 set1.addAttribute("value", "14400");  
//	    	 set1.addAttribute("link", "n-jsChart.html");  
//	    	 
//	    	 Element set2 = xml.addNode(chart, "set");
//	    	 set2.addAttribute("label", "弹弹糖");  
//	    	 set2.addAttribute("value", "24000");  
//	    	 set2.addAttribute("toolText", "toolText");  
//	    	 
//	    	 Element set3 = xml.addNode(chart, "set");
//	    	 set3.addAttribute("label", "帝国文明");  
//	    	 set3.addAttribute("value", "19600");  
//	    	 
//	    	 Element set4 = xml.addNode(chart, "set");
//	    	 set4.addAttribute("label", "君王棱");  
//	    	 set4.addAttribute("value", "85764");  
//	    	 
//	    	 System.out.println(xml.getXML());
	    	 
	    	 System.out.println(URLEncoder.encode(")"));
	    	 System.out.println(URLDecoder.decode("%3B"));
		}
	     
	     
}
